#定义了一个叫做states的集合，里面有美国的州名和对应州的简写
states = {
    'Oregon':'OR',
    'Florida':'FL',
    'California':'CA',
    'New York':'NY',
    'Michigan':'MI'
}
#定义城市的集合，key是州的缩写，value是代表的城市
cities={
    'CA':'San Francisco',
    'MI':'Detroit',
    'FL':'Jacksonville'
}

cities['NY'] = 'New York'                       #cities增加键值对，key是'NY’,value是‘New York’
cities['OR'] = 'Portland'                       #cities增加键值对，key是'OR’,value是‘Portland’
print('-'*10)                                   #输出10个‘-’
print("NY State has: ",cities['NY'])            #输出“NY State has: New York”
print("OR State has: ",cities['OR'])            #输出“OR State has: Portland”
print('-'*10)                                   #输出10个-
print("Michigan's abbreviation is: ",states['Michigan'])#输出“Michigan's abbreviation is:MI”
print("Florida's abbreviation is: ",states['Florida'])  #输出“Florida's abbreviation is: FL”
print('-'*10)                                   #输出10个-
print("Michigan has: ",cities[states['Michigan']])      #输出“Michigan has: Detroit”
print("Florida has: ",cities[states['Florida']])        #输出“Florida has: Jacksonville”
print('-'*10)                                           #输出10个-
for state,abbrev in list(states.items()):               #遍历字典states，.item（）会让字典里面的键值对变成元素是（key,value）的元组
    print(f"{state} is abbreviated {abbrev}")           #输出"州名 is abbreviated 缩写名"
print('-'*10)                                           #输出10个-
for abbrev,city in list(cities.items()):                #遍历字典cities，.item（）会让字典里面的键值对变成元素是（key,value）的元组
    print(f"{abbrev} has the city {city}")              #输出"缩写名 has the city 城市名"

print('-'*10)                                           #输出10个-
for state,abbrev in list(states.items()):               #遍历字典states，.item（）会让字典里面的键值对变成元素是（key,value）的元组
    print(f"{state} state is abbreviated {abbrev}")     #输出"州名 state is abbreviated 缩写"
    print(f"and has city {cities[abbrev]}")             #输出"and has city 城市名“
print('-'*10)                                           #输出10个-
state = states.get('Texas')                             #在states里面寻找key为Texas的项
if state == None:                                       #如果没有找到
    print("Sorry,no Texas")                             #输出"Sorry,no Texas"

city = cities.get('TX','Does Not Exist')                #查找cities里面的key‘TX’，当不存在时，返回Does Not Exist赋值给city
print(f"The city for the state 'TX' is :{city}")        #输出”The city for the state 'TX' is :{city}“